package org.example.myerp.controller;

import org.example.myerp.pojo.PageMyself;
import org.example.myerp.pojo.*;
import org.example.myerp.service.ProInformationService;

import org.example.myerp.until.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * ��Ʒ��������Ϣ�����Ʋ㡿
 * @author DELL
 *
 */
//@CrossOrigin(methods = { RequestMethod.POST, RequestMethod.GET }, allowCredentials = "true", allowedHeaders = "*")

@RestController
@RequestMapping("/design/proInformation")
public class ProInformationController {
	@Autowired
    ProInformationService proInformationService;
    @Autowired
    RedisUtil redisUtil;
	/**
	 * ��Ӳ�Ʒ��Ϣ����Ϣ
	 * ��Ӳ�Ʒ��Ϣ������
	 * ��Ӳ�Ʒ��������Ƶ���
	 * @param proInformation
	 * @param proInfoAsset
	 * @return
	 */
	@RequestMapping("/getInsertProInformation")
	@ResponseBody
	public Integer getInsertProInformation(ProInformation proInformation, ProInfoAsset proInfoAsset) {
		if(proInformation.getMfr() == "") {
			proInformation.setMfr(null);
		}
		if(proInformation.getProjName() == "") {
			proInformation.setProjName(null);
		}
		if(proInformation.getMfr() == "") {
			proInformation.setMfr(null);
		}
		if(proInformation.getUnit() == "") {
			proInformation.setUnit(null);
		}
		if(proInfoAsset.gettName() == "") {
			proInfoAsset.settName(null);
		}
		if(proInfoAsset.getUint() == "") {
			proInfoAsset.settName(null);
		}
		if(proInfoAsset.getMkrList() == "") {
			proInfoAsset.setMkrList(null);
		}
		if(proInfoAsset.getProdes() == "") {
			proInfoAsset.setProdes(null);
		}
		if(proInfoAsset.getDenjiper() == "") {
			proInfoAsset.setDenjiper(null);
		}

		Integer row = proInformationService.getInsertProInformationMessage(proInformation,proInfoAsset);
		return row;
	}

	/**
	 * ��ѯȫ��δ���˵�ȫ����Ʒ��Ϣ
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/getSelectAllProInformationByReviewSign")
	@ResponseBody
	public PageMyself<ProInformation> getSelectAllProInformationByReviewSign(Integer pageNum, Integer pageSize){
		PageMyself<ProInformation> page = proInformationService.getSelectAllProInformationByReviewSign((pageNum-1)*pageSize,pageSize);
		return page;
	}

	/**
	 *  ��ѯȫ���Ѹ��˲��Ҳ�Ʒ����Ϊ��Ʒ��ȫ����Ʒ��Ϣ������ҳ��
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/selectAllProInformationByReviewSignAndyongType")
	@ResponseBody
	public PageMyself<ProInformation> selectAllProInformationByReviewSignAndyongType(Integer pageNum, Integer pageSize){
		PageMyself<ProInformation> page = proInformationService.getSelectAllProInformationByReviewSignAndyongType((pageNum-1)*pageSize,pageSize);
		return page;
	}



	/**
	 * ���ݲ�Ʒ��Ų�ѯ��Ʒ����Ϣ
	 * @param pId
	 * @return
	 */
	@RequestMapping("/getSelectProInformationByPId")
	@ResponseBody
	public ProInformation getSelectProInformationByPId(Integer pId) {
		System.out.println(pId);
		ProInformation proInformation = proInformationService.getSelectProInformationByPId(pId);
		return proInformation;
	}

	/**
	 * ��ѯ��Ʒ����Ϊ���ϵ�ȫ����Ϣ
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/selectProductTypeByMaterials")
	@ResponseBody
	public PageMyself<ProInformation> selectProductTypeByMaterials(Integer pageNum, Integer pageSize) {
		PageMyself<ProInformation> page = proInformationService.getSelectProductTypeByMaterials((pageNum-1)*pageSize, pageSize);
		return page;
	}
}
